package com.tangding.hprose.api.server.command.impl.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.tangding.common.exception.GException;
import com.tangding.common.tools.ErrorConstants;
import com.tangding.common.utils.JacksonUtil;
import com.tangding.common.utils.Utils;
import com.tangding.hprose.api.server.command.Command;
import com.tangding.hprose.api.server.command.Response;
import com.tangding.service.dao.user.UserRepository;
import com.tangding.service.entity.user.User;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年12月2日_下午6:00:28
 *
 */
@Component
public class UpdateUser implements Command{

	@Autowired
	UserRepository userRepository;
	
	@Override
	public Response exe(Object... params) throws GException {
		String uid = JacksonUtil.get(params[0], "cid.selectItem.key", true);
		User user = userRepository.getUserByUid(uid);
		if (user == null) {
			throw new GException(ErrorConstants.USER_NOT_FOUND);
		}
		
		String password = JacksonUtil.get(params[0], "password", true);
		user.setPassword(Utils.getMD5(Utils.getMD5(password)));
		userRepository.updateUser(user);
		return doResponseSucc();
	}

}
